
package com.wisdytech.common.utils;

import java.util.UUID;

import com.wisdytech.linkdcs.equipment.model.CollectionParam;

/**
 * 设备和参数主键生成工具类
 * @author dlb
 *
 */
public class EquipmentKeyUtils {
	
	
	/**
	 * 生成参数主键key
	 * @param eqCode 设备类别编码
	 * @param param 设备参数信息
	 * @return
	 */
	public static String getParamKey(String eqModelCode,CollectionParam param) {
		
		String pkId="";
		
		//根据类型判断对应的生成规则
		switch(param.getCollectionType()) {
		
		case "1"://PLC
			StringBuilder plc =new StringBuilder();
			plc.append(eqModelCode.trim());
			plc.append(param.getPlcAddr().trim());
			pkId=plc.toString();
			break;
		case "2"://文件
			/*StringBuilder file =new StringBuilder();
			file.append(eqCode.trim());
			file.append(param.);
			pkId=md5Util.getMD5ofStr(file.toString());*/
			
			pkId=UUID.randomUUID().toString();
			break;
		case "3"://数据库
			StringBuilder database =new StringBuilder();
			database.append(eqModelCode.trim());
			database.append(param.getDatabaseParamAddr());
			pkId=database.toString();
			
			break;
		case "4"://上位机
			StringBuilder upper =new StringBuilder();
			upper.append(eqModelCode.trim());
			upper.append(param.getUpperParamField());
			pkId=upper.toString();
			break;
		default:
			pkId=UUID.randomUUID().toString();
		  	
		}	
		
		
		return MD5Util.getDigest(pkId);
	}
	
	
}
